package com.test;

import java.util.ArrayList;
import java.util.Scanner;

public class ArrayListTest5 {
    public static void main(String[] args) {
        //定义一个集合，添加一些学生对象，并进行遍历
        //1.创建集合
        ArrayList<Student> list = new ArrayList<>();
        //2.录入学生的信息并添加到集合当中
        Scanner scanner = new Scanner(System.in);
        for (int i = 0; i < 3; i++) {
            Student student = new Student();
            System.out.println("请输入学生的姓名:");
            String name = scanner.next();
            System.out.println("请输入学生的年龄:");
            int age = scanner.nextInt();
            student.setName(name);
            student.setAge(age);
            list.add(student);
        }
        //3.遍历集合
        for (int i = 0; i < list.size(); i++) {
            //i 索引
            //list.get(i)   元素
            Student student = list.get(i);
            System.out.println("姓名为:"+student.getName()+",年龄为:"+student.getAge());
        }
    }
}
